package com.leyou.item.controller;


import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.entitiy.TbSpecGroup;
import com.leyou.item.service.TbSpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 规格参数的分组表，每个商品分类下有多个规格参数组 前端控制器
 * </p>
 *
 * @author HM
 * @since 2021-06-16
 */
@Controller
@RequestMapping("/spec")
public class TbSpecGroupController {
    @Autowired
    private TbSpecGroupService specService;

    /**
     * 查询规格组信息
     * 根据分类id
     * @param id
     * @return
     */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> findSpecGroupByCategoryId(@RequestParam(name = "id") Long id){
        List<SpecGroupDTO> groupDTOList = specService.findSpecGroupByCategoryId(id);
        return  ResponseEntity.ok(groupDTOList);
    }

    @PostMapping("/group")
    public ResponseEntity<Void> add(@RequestBody TbSpecGroup tbSpecGroup){
        specService.add(tbSpecGroup);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @PutMapping("/group")
    public ResponseEntity<Void> update(@RequestBody TbSpecGroup tbSpecGroup){
        specService.updat(tbSpecGroup);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @DeleteMapping("/group/{id}")
    public ResponseEntity<Void> delete(@PathVariable(value = "id") Long id){
        specService.delete(id);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
}

